//
//  main.c
//  结构体与函数
//
//  Created by ws on 2017/7/25.
//  Copyright © 2017年 王松. All rights reserved.
//

#include <stdio.h>

/**
 1.结构体变量作为函数参数
 */
struct Person{
    char *name;
    int age;
    float height;
};
/**
 写一个函数打印结构体 Person
 */
void printPerson(struct Person person){
     printf("name = %s,age = %d,height = %.2f\n",person.name,person.age,person.height);
}
/**
 结构体变量作为函数参数传递是值传递
 */
void changePerson(struct Person person){
    person.age = 30;
}
/**
 结构体指针作为函数参数是地址传递
 */
void changePerson2(struct Person *personPointer){
    personPointer->age = 20;
}
/**
 结构体数组作为函数参数是地址传递
 */
void changePersons(struct Person persons[]){
    persons[0].age = 23;
}
void printPersons(struct Person persons[],int length){
    for (int i = 0; i < length; i++) {
       printf("name = %s,age = %d,height = %.2f\n",persons[i].name,persons[i].age,persons[i].height);
    }
}

int main(int argc, const char * argv[]) {
    struct Person person = (struct Person){"xx",10,40};
//    changePerson(person);
//    changePerson2(&person);
//    printPerson(person);
    
    struct Person persons[3]  = {{"小泉",2,0.3}, {"晋三",1,0.2}};
    int len = sizeof(persons) / sizeof(struct Person);
    changePersons(persons);
    printPersons(persons,len);
    return 0;
}
